<?php
/**
* Display the transactions in a table fashion
*
* @author       Fabrice Douteaud <admin@clearbudget.net>
* @package      snippets
* @access       public
*/

/***********************************************************************

  Copyright (C) 2008  Fabrice Douteaud (admin@clearbudget.net)

    This file is part of ClearBudget.

    ClearBudget is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ClearBudget is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ClearBudget.  If not, see <http://www.gnu.org/licenses/>.


************************************************************************/
//prevent direct access
if(!defined('ENGINEON')) die('Direct access forbidden');
// build the back link URL to enable to be back to this list from a sub page (i.e.: the break transaction page)
$backLink = $context->action.'_ajax=1_monthSelected='.$context->monthSelected.'_debit='.$context->debit.'_categorySelected='.$context->categorySelected.'_keyWord='.$context->keyWord;
?>
<table class="tableReport">
<caption><?php echo $title; ?></caption>
<?php
  $alt = '';
  echo '<tr><th><u>'.$keys->text_payee.'</u></th><th><u>'.$keys->text_memo.'</u></th><th><u>'.$keys->text_amountLong.'</u></th><th><u>'.$keys->text_operationDate.'</u></th><th><u>'.$keys->text_categoryNameLong.'</u></th><th colspan="2"></th></tr>';
  foreach($results as $result) {
  if($alt == "") $alt = 'class="alt"';
  else $alt = '';
  // presentation row
  echo '<tr id="tr-'.$result['id'].'">';
  echo '<td '.$alt.' style="width:500px">'.$result['payee'].'</td>';
  echo '<td '.$alt.'  style="width:300px">';
  echo ' <input class="commentEntry" type="text" size="20" id="commentEntry'.$result['id'].'" value="'.$result['comments'].'"> <a href="#" commentEntrySave="true" id="'.$result['id'].'">'.$keys->link_save.'</a>';
  echo '<span><img class="hidden" id="commentLoading-'.$result['id'].'" src="style/icons/icon_Loading.gif"></span></td>';
  echo '<td '.$alt.' style="width:70px">'.class_currency::getCurrencySymbol().$report->formatNumber($result['amount']).'</td>';
  echo '<td '.$alt.' style="width:170px">'.utf8_encode(strftime('%A %d %B %y', strtotime($result['operationDate']))).'</td>';
  echo '<td '.$alt.' style="width:250px">';
  echo '<select id="categorySelector'.$result['id'].'" class="categorySelector">';
  // list all possible categories
  foreach($categories as $id=>$name) {
    // show the uncategorized option only is item is already uncategorized
    if($id == 1 && $result['category'] != 1) continue;
    echo '<option value="'.$id.'"';
    if($result['category'] == $id) echo ' selected="selected"';
    echo '>'.$name.'</option>';
    }
  echo '</select> <a href="#" categorySelectorSave="true" id="'.$result['id'].'">'.$keys->link_save.'</a><span><img class="hidden" id="catLoading-'.$result['id'].'" src="style/icons/icon_Loading.gif"></span>';
  echo '</td>';
  // the break transaction button
  echo '<td '.$alt.'><a href="#" title="'.$keys->linkText_breakTransactionLink.'" breakTransaction="true" backLink="'.$backLink.'" id="'.$result['id'].'">';
  if($result['parentId'] > 0) echo '<img src="style/icons/coins.png">';
  else echo '<img src="style/icons/coins_add.png">';
  echo '</a></td>';
  // the add to schedule button
  echo '<td '.$alt.'><a href="#" title="'.$keys->linkText_taskReminderLink.'" taskScheduler="true" backLink="'.$backLink.'" trnId="'.$result['id'].'">';
  echo '<img src="style/icons/clock_add.png">';
  echo '</a></td>';
  echo '</tr>';
  }
?>
</table>